/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import interfaces.InternationalizableEntity;
import interfaces.InternationalizableEntityDescription;
import java.io.Serializable;
import java.util.List;
import java.util.List;
import java.util.Locale;
import javax.faces.context.FacesContext;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "educational_status", catalog = "facetoframe", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "EducationalStatus.findAll", query = "SELECT e FROM EducationalStatus e ORDER BY e.value"),
    @NamedQuery(name = "EducationalStatus.findByIdEducationalStatus", query = "SELECT e FROM EducationalStatus e WHERE e.idEducationalStatus = :idEducationalStatus"),
    @NamedQuery(name = "EducationalStatus.findByDescription", query = "SELECT e FROM EducationalStatus e WHERE e.description = :description"),
    @NamedQuery(name = "EducationalStatus.findByValue", query = "SELECT e FROM EducationalStatus e WHERE e.value = :value")})
public class EducationalStatus implements Serializable,InternationalizableEntity {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "educationalStatus")
    private List<EducationalStatusDescription> educationalStatusDescriptionList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_EDUCATIONAL_STATUS")
    private Integer idEducationalStatus;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 40)
    @Column(name = "DESCRIPTION")
    private String description;
    @Column(name = "VALUE")
    private Integer value;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "status")
    private List<CandidateEducationalInfo> candidateEducationalInfoList;

    public EducationalStatus() {
    }

    public EducationalStatus(Integer idEducationalStatus) {
        this.idEducationalStatus = idEducationalStatus;
    }

    public EducationalStatus(Integer idEducationalStatus, String description) {
        this.idEducationalStatus = idEducationalStatus;
        this.description = description;
    }

    public Integer getIdEducationalStatus() {
        return idEducationalStatus;
    }

    public void setIdEducationalStatus(Integer idEducationalStatus) {
        this.idEducationalStatus = idEducationalStatus;
    }

    @Override
    public String getDescription() {
//        String resDescription=description;
//        Locale currentLocale=FacesContext.getCurrentInstance().getViewRoot().getLocale();
//        if(!getEducationalStatusDescriptionList().isEmpty() && !currentLocale.equals(Locale.ENGLISH)){
//            String localeCode=currentLocale.getLanguage();
//            for(EducationalStatusDescription cd:getEducationalStatusDescriptionList()){
//                if(cd.getLanguage().getCode().equals(localeCode)){
//                    resDescription=cd.getDescription();
//                }
//            }
//        }
//        return resDescription;
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    @XmlTransient
    public List<CandidateEducationalInfo> getCandidateEducationalInfoList() {
        return candidateEducationalInfoList;
    }

    public void setCandidateEducationalInfoList(List<CandidateEducationalInfo> candidateEducationalInfoList) {
        this.candidateEducationalInfoList = candidateEducationalInfoList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idEducationalStatus != null ? idEducationalStatus.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof EducationalStatus)) {
            return false;
        }
        EducationalStatus other = (EducationalStatus) object;
        if ((this.idEducationalStatus == null && other.idEducationalStatus != null) || (this.idEducationalStatus != null && !this.idEducationalStatus.equals(other.idEducationalStatus))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.EducationalStatus[ idEducationalStatus=" + idEducationalStatus + " ]";
    }

    @XmlTransient
    public List<EducationalStatusDescription> getEducationalStatusDescriptionList() {
        return educationalStatusDescriptionList;
    }

    public void setEducationalStatusDescriptionList(List<EducationalStatusDescription> educationalStatusDescriptionList) {
        this.educationalStatusDescriptionList = educationalStatusDescriptionList;
    }

    @Override
    public Integer getId() {
        return getIdEducationalStatus();
    }

    @Override
    public List<? extends InternationalizableEntityDescription> getDescriptionsList() {
        return getEducationalStatusDescriptionList();
    }
    
}
